package com.hualan.zhsq.controller.information;



import com.hualan.zhsq.entity.information.ResidentInfo;
import com.hualan.zhsq.service.information.ResidentInfoService;
import com.hualan.zhsq.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/residentInfo")
public class ResidentInfoController {


    @Autowired
    private ResidentInfoService residentInfoService;
    /**
     * 新增住户
     * @param residentInfo
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody ResidentInfo residentInfo){
        int rows = residentInfoService.add(residentInfo);
        return rows>0?Result.success():Result.error();
    }

    /*
     * 编辑住户
     * @param residentInfo
     * @return
     */

    @RequestMapping("/edit")
    public Result edit(@RequestBody ResidentInfo residentInfo){
        int rows = residentInfoService.edit(residentInfo);
        return rows>0?Result.success():Result.error();
    }

    /**
     * 根据id删除住户
     * @param id
     * @return
     */
    @RequestMapping("/remove")
    public Result remove(Integer id){
        int rows = residentInfoService.remove(id);
        return rows>0?Result.success():Result.error();
    }

    /**
     * 批量删除住户
     * @param ids
     * @return
     */
    @RequestMapping("/removeBatch")
    public Result removeBatch(Integer[] ids){
        int rows = residentInfoService.removeBatch(ids);
        return rows>0?Result.success():Result.error();

    }

    /**
     * 根据id查找住户
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result<ResidentInfo> findById(Integer id){
        return Result.success(residentInfoService.findById(id));
    }

    /**
     * 无条件查找全部住户
     * @return
     */
    @RequestMapping("/find")
    public Result<List<ResidentInfo>> find(){
        return Result.success(residentInfoService.find());
    }

    /**
     * 分页查找全部房屋，带条件
     * @param pageNum
     * @param pageSize
     * @param residentInfo
     * @return
     */
    @RequestMapping("/findPage")
    public Result<Map<String,Object>> findPage(Integer pageNum, Integer pageSize, ResidentInfo residentInfo){
        Map<String, Object> map = residentInfoService.findPage(pageNum, pageSize, residentInfo);
        return Result.success(map);
    }
}
